import resource from "./Resources.js"
class ResourceLoader {
  constructor() {
    this.map = new Map(resource)
    for(let [key, value] of this.map) {
      const image = new Image()
      image.src = value
      this.map.set(key, image)
    }
  }
  onloaded(callback) {
    let count = 0
    for(let value of this.map.values()) {
      value.onload = () => {
        count++
        if(count >= this.map.size) {
          callback(this.map)
        }
      }
    }
  }
  static create() {
    return new ResourceLoader
  }
}
export default ResourceLoader
